<?php
/**
* @version		$Id: router.php 10127 2008-03-11 20:46:31Z ircmaxell $
* @package		Joomla
* @copyright	Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license		GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/

function JanewsBuildRoute(&$query)
{
	$segments = array();

	if(isset($query['view']))
	{
		//$segments[] = "news";//$query['view'];
		unset($query['view']);
	};

	if (isset($query['layout'])){
	  //$segments[] = $query['layout'];
	  unset($query['layout']);
	}
	if(isset($query['id'])){
		/*$db = &JFactory::getDBO();
		$sql = "SELECT alias FROM #__sections WHERE id=".$query['id'];
		$db->setQuery($sql);
		$section = $db->loadObjectList();
		$segments[] = $section[0]->alias;*/
		unset($query['id']);
	};

	return $segments;
}

function JanewsParseRoute($segments)
{
	$vars = array();

	// Count route segments
	$count = count($segments);
  $db = &JFactory::getDBO();
	$alias = str_replace(':', '-', $segments[$count-1]);
	$sql = "SELECT id FROM #__sections WHERE alias='$alias'";
	$db->setQuery($sql);
	$sections = $db->loadObjectList();
	if(!$sections) $sections[0]->id = 0;
	//Standard routing for sections
	switch ($segments[0]) {
	  case "news":
	    $vars['view']  = "section";
	    break;
	}
	$vars['id']    = $sections[0]->id;
	return $vars;
}
